using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Graphics;

using TInput = ContentExtentions.GravityModelHolder;

namespace ContentExtentions
{
    /// <summary>
    /// This class will be instantiated by the XNA Framework Content Pipeline
    /// to import a file from disk into the specified type, TImport.
    /// 
    /// This should be part of a Content Pipeline Extension Library project.
    /// </summary>
    [ContentImporter(".grav", DisplayName = "GravityModel Importer", DefaultProcessor = "GravityNormalRotateProcessor")]
    public class GravityModelImporter : ContentImporter<GravityModelHolder>
    {
        public override TInput Import(string filename, ContentImporterContext context)
        {
            String data = File.ReadAllText(filename);
            String[] values = data.Split(new char[] { ';' });

            Vector3 gravity = new Vector3(float.Parse(values[0]), float.Parse(values[1]), float.Parse(values[2]));
            String modelFileName = values[3];
            modelFileName = modelFileName.Trim();

            FbxImporter fbxImporter = new FbxImporter();
            NodeContent modelRootNode = fbxImporter.Import( modelFileName + ".fbx", context );

            GravityModelHolder gravityModelHolder = new GravityModelHolder();
            gravityModelHolder.ModelRootNode = modelRootNode;
            gravityModelHolder.Gravity = gravity;

            return gravityModelHolder;
        }
    }
}